package com.example.demo.config;

import com.google.common.collect.Range;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Slf4j
@Component
public class CustomRangeShardingAlgorithm implements RangeShardingAlgorithm<Long> {

    @Override
    public Collection<String> doSharding(Collection<String> tableNames, RangeShardingValue<Long> shardingValue) {
        if (CollectionUtils.isNotEmpty(tableNames) && shardingValue != null && shardingValue.getValueRange() != null) {
            try {
                Range<Long> value = shardingValue.getValueRange();
                // todo

            } catch (Exception e) {
                log.error("找表分片异常!");
            }
        }
        //throw new IllegalArgumentException("找不到匹配的表分片");
        return null;
    }

}
